Concentre.modulesHashTable['http://www.w3.org/2002/xforms'] =
Concentre.XForms = {
		options: {
			basePath: null,
			xmlDocument: null
		},
	
		innerModels: [],

		initialize: function(parent) {	
			var doc = parent.xmlDocument;

			var expr = new XPath('//xforms:*');
			var havexforms = expr(doc.documentElement, QName);
	
			if (!havexforms) {
				return;
			}
						
			var expr = new XPath('//xforms:model');
			var models = expr(doc.documentElement, QName)
			
			var n = null;

			if (models.length==0) throw new Exception(Concentre.Factory.i18n.translate('IDS_MODEL_NOT_FOUND'));
					
			for ( var i=models.length; --i>=0; ) {
				new Concentre.XForms_Element_Head_Model(models[i], this, this);
			}
						
			this.defaultModel = this.innerModels[0];
			
		},
		
		start: function() {
		
			for ( var i=this.innerModels.length; --i>=0; ) {
				var model = this.innerModels[i];
				if (model.defaultInstance==null) throw new Exception(Concentre.Factory.i18n.translate('IDS_DEFAULT_INSTANCE_NOT_FOUND'));

				model.rebuild    ();
    			model.recalculate();
    			model.revalidate ();
    			model.refresh    ();

  	  			model.fireEvent("xforms-model-construct");
      			model.fireEvent("xforms-model-construct-done");
      			model.fireEvent("xforms-ready");
      		}
      		 
		},

   		bind: function(node, control, model, parent) {
		
		// binding to xforms
		var bind;

		if (!parent) parent = this.defaultModel;
		if (!model) model = this.defaultModel;
	
		var modelAttribute = Concentre.objectsById[ node.getAttribute( 'model' ) ];
		if (modelAttribute!=null) model = modelAttribute;

		
        /*if (control instanceof Concentre.XForms_Element_Action_Abstract) {
			//Concentre.bind(n, parent, model, control);
			return;
        }*/

		var valueAttribute = node.getAttribute('value');		
		
		if (valueAttribute) {
			/*
			node.setAttribute('calculate', valueAttribute);
			var binding = new Concentre.XForms_Binding(node, model, parent);
			control.binding = binding;			
			binding.controls.push( control );
			Concentre.bind(node, control, model, parent);
			*/		
			return;
		} else if ( bind = node.getAttribute('bind') ) {
			
			var binding = Concentre.objectsById[ bind ];
			assert(bind, "Unknown bind : " + bind );
			
			control.binding = binding;
			binding.controls.push( control );
		} else {
			var refAttribute = node.getAttribute('ref');
			var nodeSetAttribute = node.getAttribute('nodeset');
		
			
			if (refAttribute || nodeSetAttribute) {
				/*
				var type = refAttribute!=null?'ref':'nodeset';
				var expr = refAttribute!=null?refAttribute:nodeSetAttribute;
				*/
				
				var binding = new Concentre.XForms_Binding(node, model, parent);
				
				
				binding.controls.push( control );
				control.binding = binding;
				
			} else {
				Concentre.bind(node, control, model, parent);
				return;
			}
		}
		
		Concentre.bind(node, control, model, binding );
		
		
   		},
		
		exception: function(event, message,cause) {
			throw new Exception(message,cause)
		},
		
		toString: function() {
			return '[ Module Concentré XForms ]';
		}
};
